package com.jtpay.unionpay.product.http.dataStructure;

import com.google.gson.Gson;
import okhttp3.MediaType;
import okhttp3.RequestBody;

import java.util.HashMap;

/**
 * Created by Administrator on 2018/1/25.
 * JSON的装换类与RequestBody的包装类
 */

public class JsonParams extends HashMap<String, String> {
    public RequestBody buildRequestBody() {
        return RequestBody.create(MediaType.parse("application/json; charset=utf-8"), new Gson().toJson(this));
    }

    public String getJsonObject() {
        return new Gson().toJson(this);
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("JsonParams{");
        for (String s : keySet()) {
            builder.append(" key: " + s + " value: " + get(s));
        }
        builder.append("}");
        return builder.toString();
    }
}
